import { http } from "@/utils/http";
import type { ResultTable } from "@/api/type";
import type { FormItemProps } from "@/views/learn/category/utils/types";

const modulePath = "/learn";
type result = {
  code: number;
  msg: string;
  data: FormItemProps;
};

/** 分页列表 */
export const getCategoryList = (params?: object) => {
  return http.request<ResultTable>("get", modulePath + "/categories/list", {
    params
  });
};

/** 所有数据 */
export const getCategoryAllList = (params?: object) => {
  return http.request<ResultTable>("get", modulePath + "/categories/all", {
    params
  });
};

/** 新增 */
export const categoryAdd = (data?: { name: string; rank: number }) => {
  return http.request<result>("post", modulePath + "/categories/add", { data });
};

/** 修改 */
export const categoryUpdate = (data?: FormItemProps) => {
  return http.request<result>("put", modulePath + "/categories/update", {
    data
  });
};

/** 删除 */
export const categoryDel = (data: object) => {
  return http.request<result>("delete", modulePath + "/categories/delete", {
    data
  });
};
